package com.fyt.controller.fencing;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fyt.controller.utils.Code;
import com.fyt.controller.utils.Result;
import com.fyt.entity.Enclosure;
import com.fyt.entity.Fencing;
import com.fyt.entity.Pasture;
import com.fyt.mapper.FencingMapper;
import com.fyt.service.enclosure.EnclosureService;
import com.fyt.service.fencing.FencingService;
import com.fyt.service.pasture.PastureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api("围栏管理")
@RestController
public class fencingControler {
    @Autowired
    private EnclosureService enclosureService;
    @Autowired
    private PastureService pastureService;
    @Autowired
    private FencingMapper fencingMapper;
    @Autowired
    private FencingService fencingService;

    @ApiOperation("查询未禁用的牧场")
    @GetMapping("/api/fencing/getPasture")
    public Result getPastureList(@RequestBody Map<String, String> map){
        return pastureService.getIsenablePastureList(map);
    }
    @ApiOperation("根据牧场id查询未禁用的圈舍")
    @GetMapping("/api/fencing/getEnclosure")
    public Result getEnclosure(@RequestBody Map<String, String> map){
        String PastureId = map.get("PastureId");
        List<Enclosure> enclosureList = enclosureService.getEnclosureListByPastureId(PastureId);
        return new Result(enclosureList, Code.get_ok,enclosureList!=null?"success":"此牧场无圈舍或系统错误");
    }
    @ApiOperation("根据圈舍id查询未禁用的围栏")
    @GetMapping("/api/fencing/getFencing/{id}")
    public Result getFencingByEnclosureId(@PathVariable String id){
        QueryWrapper<Fencing> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("e_id",id);
        List<Fencing> fencings = fencingMapper.selectList(queryWrapper);
        return new Result(fencings,Code.get_ok,null);
    }
    @ApiOperation("新增围栏")
    @PostMapping("/api/fencing/addFencing")
    public Result addFencing(@RequestBody Map<String,String>map){
       return fencingService.addFencing(map);
    }

}
